﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Heroius.Indexer
{
    public partial class TxQuery : Form
    {
        public TxQuery()
        {
            InitializeComponent();
        }

        #region Ability Modification

        private void ChbKey_CheckedChanged(object sender, EventArgs e)
        {
            TbKey.Enabled = ChbKey.Checked;
        }

        private void ChbCata_CheckedChanged(object sender, EventArgs e)
        {
            TbCata.Enabled = ChbCata.Checked;
        }

        private void RbID_CheckedChanged(object sender, EventArgs e)
        {
            TbID.Enabled = RbID.Checked;
        }

        private void RbOr_CheckedChanged(object sender, EventArgs e)
        {
            PnlOr.Enabled = RbOr.Checked;
        }
        #endregion

        public bool Exec = false;
        public bool ByID { get { return RbID.Checked; } }
        public string IDText { get { return TbID.Text; } }
        public bool WithCata { get { return ChbCata.Checked; } }
        public string CataText { get { return TbCata.Text; } }
        public bool WithKey { get { return ChbKey.Checked; } }
        public string KeyText { get { return TbKey.Text; } }
        public bool ShowAll { get { return RbAll.Checked; } }

        private void BtnOK_Click(object sender, EventArgs e)
        {
            if (ByID)
            {
                if (string.IsNullOrWhiteSpace(TbID.Text))
                {
                    MessageBox.Show("ID 不能为空");
                    return;
                }
            }
            else if (ShowAll)
            { /*do nothing*/ }
            else
            {
                bool neither = true;
                if (WithCata)
                {
                    neither = false;
                    if (string.IsNullOrWhiteSpace(TbCata.Text))
                    {
                        MessageBox.Show("分类 不能为空");
                        return;
                    }
                }
                if (WithKey)
                {
                    neither = false;
                    if (string.IsNullOrWhiteSpace(TbKey.Text))
                    {
                        MessageBox.Show("关键字 不能为空");
                        return;
                    }
                    if (TbKey.Text.Contains(' '))
                    {
                        MessageBox.Show("关键字 只能是一个（不可包含空格）");
                        return;
                    }
                }
                if (neither)
                {
                    MessageBox.Show("必须选择一项查询条件");
                    return;
                }
            }

            Exec = true;
            this.Close();
        }

        private void BtnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
